﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DynCMS.NET.Core.Entities;
using DynCMS.NET.Core.Entities.Base;
using DynCMS.NET.Core.Interfaces;
using DynCMS.NET.DataAccess.Implementation;

namespace DynCMS.NET.DataAccess.Repos
{
    public class GenericAutoIdRepository<TEntity> :
        GenericRepository<TEntity>,
        IIdentityRepository<TEntity>
        where TEntity : EntityWithAutoId
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="T:GenericRepository"/> class.
        /// </summary>
        public GenericAutoIdRepository(DataContext context)
            : base(context)
        {
            //this.context = context;
            //table = this.context.Set<TEntity>();
        }

        /// <summary>
        /// Gets the specified id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public virtual TEntity Get(int id)
        {
            return table.Find(id);
        }

        /// <summary>
        /// Returns entity with specified id
        /// </summary>
        /// <param name="key"></param>
        /// <returns>Entity with provided id</returns>
        public override TEntity Get(TEntity key)
        {
            return this.Get(key.Id);
        }
    }
}